#ifndef __COMMON_DEF_H__
#define __COMMON_DEF_H__


//define __func__ macro for VC complier
#ifdef _MSC_VER
#if (_MSC_VER<1300)//VC6 and before
#define __func__ "FUNCTION" 
#elif (_MSC_VER > 1200)//VC6 above, not include VC6
#define __func__ __FUNCTION__
#endif
#endif

//define DEBUGOUT for different program
#if defined(WIN32)
#define DEBUGOUT printf
#elif defined(CU_VERSION)//not output debug info in CUnit 
#define DEBUGOUT(format,...)
#else
#define DEBUGOUT printf
#endif

//assert for embedded  system
#define return_if_fail(p) if(!(p))           \
{DEBUGOUT("%s:%d Warning: "#p" failed.\n",   \
	__func__, __LINE__); return;}
#define return_val_if_fail(p, ret) if(!(p))  \
{DEBUGOUT("%s:%d Warning: "#p" failed.\n",   \
	__func__, __LINE__); return (ret);}

// simple macro for extern "C"
#ifdef __cplusplus
#define EXTERN_C_BEGIN extern "C" {
#define EXTERN_C_END   }
#else
#define EXTERN_C_BEGIN
#define EXTERN_C_END
#endif/*__cplusplus*/

#define MALLOC(a) malloc(a)
#define FREE(a) free(a)
#define SAFE_FREE(p) if(p != NULL) {FREE(p); p = NULL;}

#endif
